package java04;
class MyStack{
    private Object[] ele;
    private int index;
    public MyStack() {
        this.ele = new Object[10];
            this.index = -1;
    }

    public Object[] getEle() {
        return ele;
    }

    public void setEle(Object[] ele) {
        this.ele = ele;
    }
    //压栈
    public void push(Object obj){
        if(index == ele.length-1){
            System.out.println("栈已满，压栈失败！");
            return;
        }
        index++;
        ele[index] = obj;
        System.out.println("栈" + ele[index] + "压栈成功！ " + "栈帧指向" + index);
    }
    //弹栈
    public void pop(){
        if(index < 0){
            System.out.println("栈已空，弹栈失败！");
            return;
        }
        System.out.print("栈" + ele[index] + "以弹出!");
        ele[index] = null;
        index--;
        System.out.println(" 栈帧指向" + index);
    }
}
class Aa{}
public class ArrayTest02 {
    public static void main(String[] args){
        MyStack m = new MyStack();
        for(int i = 0; i < 12; i++){
            m.push(new Aa());
        }
        for(int i = 0; i < 13; i++){
            m.pop();
        }
    }
}
